技術問答
技術文章
iT 徵才
Tag
聊天室
2025 鐵人賽
登入/註冊
問答
文章
Tag
邦友
鐵人賽
搜尋
2021 iThome 鐵人賽
DAY
22
0
Mobile Development
麻瓜學習 iOS 開發
系列 第
22
篇
Day22:動手做一個 app 吧
13th鐵人賽
enolazxy
2021-10-07 23:57:34
737 瀏覽
分享至
前言
現在我們要用我們之前學的內容,
做一個簡單的 RecipeList APP。
實作
打開一個新的專案-RecipeList
使用 MVVM 結構
Models 代表 app 中的數據,
VIews 表示使用者界面,
ViewModels 用來管理數據和運行 view 的業務邏輯
建立一些虛假數據
刻製 UI
在 ContentView 中實例化 RecipeModel 並將它分配給變數 model ,
用列表顯示 recipes 數據:
xcode 顯示 error,
這是因為要遍歷 array 的元素時,
在 List 中我們必須指定 id,
所以我們宣告的 struct Recipe 要符合可宣告協定並且宣告一個變數 id,
保證每次都會分配一個唯一的 ID:
數據變化時自動更新 UI
這主要分為三個步驟:
step1:聲明 ViewModel 中的 RecipeModel 符合可觀察協定
step2:在 View 中放入一個包裝器
step3:放入 published 包裝器
實驗看看:
宣告一個 function:
在 ContentView 中宣告一個 button,
點擊這個 button 會印出 function 的內容:
這表示 ViewModel 中的數據改變時,
View 也隨著改變。
留言
追蹤
檢舉
上一篇
Day21:開發自己的 APP 的前置步驟
下一篇
Day23:傳入 JSON 文件
系列文
麻瓜學習 iOS 開發
共
30
篇
目錄
RSS系列文
訂閱系列文
2
人訂閱
26
Day26:TabView
27
Day27:用 EnvironmentObject 傳遞數據
28
Day28:Update the Data and the Featured View
29
Day29: Picker controller
30
Day 30 : DetailView
完整目錄
熱門推薦
{{ item.subject }}
{{ item.channelVendor }}
|
{{ item.webinarstarted }}
|
{{ formatDate(item.duration) }}
直播中
立即報名
尚未有邦友留言
立即登入留言
iThome鐵人賽
參賽組數
902
組
團體組數
37
組
累計文章數
19467
篇
完賽人數
530
人
看影片追技術
看更多
{{ item.subject }}
{{ item.channelVendor }}
|
{{ formatDate(item.duration) }}
直播中
熱門tag
看更多
15th鐵人賽
16th鐵人賽
13th鐵人賽
14th鐵人賽
17th鐵人賽
12th鐵人賽
11th鐵人賽
鐵人賽
2019鐵人賽
javascript
2018鐵人賽
python
2017鐵人賽
windows
php
c#
linux
windows server
css
react
熱門問題
【已解決】鐵人賽每天發表,還是一樣被斷賽了!?有人是一樣的嗎?
Windows 11 專業版 (筆電) 重灌
Win2008R2 AD無法派送印表機到 Win11 的電腦,可以用網域內的win11電腦部屬派送至其他成員電腦嗎?
Windows 2008 R2 AD無法派送印表機到 Window 11 的電腦
How to integrate an online electricity bill API on a website?
閱讀 [技術文章] 的需求建議~
google 試算表 App Scripts 問題
zimbra blocked using cblless.anti-spam.org.cn
OCS Inventory NG
熱門回答
Windows 2008 R2 AD無法派送印表機到 Window 11 的電腦
Windows 11 專業版 (筆電) 重灌
How to integrate an online electricity bill API on a website?
google 試算表 App Scripts 問題
Win2008R2 AD無法派送印表機到 Win11 的電腦,可以用網域內的win11電腦部屬派送至其他成員電腦嗎?
熱門文章
[為你自己學 n8n] 第 30 天,n8n 之我獨自備份 n8n!
[ Day 30 ] 資料專案的各式小撇步,私房秘訣大公開
Day 30 - 完賽總結:從 Canvas 到各式各樣的 Web API 之旅 🎉
資安入門與實務應用介紹 17:Windows 系統安全機制(UAC、BitLocker、Windows Update、Defender)
Day30 - 地獄之門,直達內核:Hell's Gate 的直接系統呼叫術(下)
IT邦幫忙
×
標記使用者
輸入對方的帳號或暱稱
Loading
找不到結果。
標記
{{ result.label }}
{{ result.account }}